<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">

<head>
    <th:block th:include="common/common_head :: commonHeader('员工管理')"/>
    <link rel="stylesheet" th:href="@{/static/js/plugins/jquery-layout/jquery.layout-latest.css}">
</head>

<body class="gray-bg">
<div class="ui-layout-west">
    <div class="main-content">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 组织机构
                </div>
                <div class="box-tools pull-right">
                    <a type="button" class="btn btn-box-tool J_menuItem" th:href="@{/modules/sys/dept/dept_list.html}" data-name="机构管理" data-ischild="true" target="_blank"><i class="fa fa-edit"></i></a>
                 <!--   <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新机构"><i class="fa fa-refresh"></i></button>-->
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="ztree" class="ztree"></div>
            </div>
        </div>
    </div>
</div>

<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-condition">
            <form id="userForm" th:action="@{/sys/user/list}" class="form-inline">
                <input type="hidden" name="deptId" id="deptId"/>
                <div class="select-list">
                    <ul>
                        <li class="col-md-3">
                            账号：<input type="text" name="username"/>
                        </li>
                        <li class="col-md-3">
                            员工名称：<input type="text" name="name"/>
                        </li>
                        <li>
                            <button id="userSearchBtn" type="button" class="btn btn-primary btn-rounded btn-sm"><i class="fa fa-search"></i>&nbsp;搜索</button>
                            <button class="btn btn-warning btn-rounded btn-sm" type="reset"><i class="fa fa-eraser"></i>&nbsp;重置</button>
                            <button id="userAdvancedSearch" type="button" class="btn btn-primary btn-rounded btn-sm" style="display: none"><i class="fa fa-caret-down"></i>&nbsp;高级搜索</button>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-info">
            <div class="btn-group hidden-xs toolbar" id="userToolBar" role="group">
                <a class="btn btn-outline btn-success btn-rounded" onclick="toAddUser()"
                   shiro:hasPermission="sys:user:save">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="toEditUser()">
                    <i class="fa fa-edit"></i> 编辑
                </a>
                <a class="btn btn-outline btn-danger btn-rounded" onclick="deleteUser()">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-outline btn-danger btn-rounded" onclick="use()">
                    <i class="fa fa-edit"></i> 启用
                </a>
                <a class="btn btn-outline btn-danger btn-rounded" onclick="unUse()">
                    <i class="fa fa-edit"></i> 禁用
                </a>
                <a class="btn btn-outline btn-danger btn-rounded" onclick="resetPwd()">
                    <i class="fa fa-edit"></i> 重置密码
                </a>
            </div>
            <table id="user">
            </table>
        </div>
    </div>
</div>
<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<script type="text/javascript" th:src="@{/static/js/plugins/jquery-layout/jquery.layout-latest.js}"></script>
<!-- Page-Level Scripts -->
<script type="text/javascript">
    var tree;
    $(function () {
        $('body').layout({west__size: 250});

        tree=ZTree.init('ztree', ctxPath+ "/sys/dept/getUserDept", {
            clickTree: function (treeId, treeNode, clickFlag) {
                $("#deptId").val(treeNode.deptId);
                searcherBS.refresh();
            },
            data: {
                key: {
                    name: "name"
                },
                simpleData: {
                    enable: true,
                    idKey: "deptId",
                    pIdKey: "parentId",
                    rootPId: null
                }
            },check: {
                enable: false
            }
        });
    });

    var searcherBS = Searcher.createBS('#user',
        [
            {checkbox: true},
            {title: 'userId',field:"userId", visible: false},
            {title: "账号", field:"username", align: 'center', valign: 'middle'},
            {title: "手机号",field:"mobile",  align: 'center', valign: 'middle'},
            {title: "姓名",field:"name",  align: 'center', valign: 'middle'},
            {title: "OA账号",field:"oaAccount",  align: 'center', valign: 'middle'},
            {title: "身份证号",field:"idNumber",  align: 'center', valign: 'middle'},
            {title: "岗位",field:"post",  align: 'center', valign: 'middle',
                formatter: Formatter.showDesc({1:'业务员', 2:'店长'}, '-')
            },
            {title: "邮箱",field:"email",  align: 'center', valign: 'middle'},
            {title: "状态", field:"status",  align: 'center', valign: 'middle',
                formatter:Formatter.showDesc({0:'禁用', 1:'正常'})},
            {title: "部门", field:"deptName",  align: 'center', valign: 'middle'},
            {title: "创建时间", field:"createTime",  align: 'center', valign: 'middle'}
        ]
    );

    /**
     * 跳转至新增页
     */
    function toAddUser() {
        var index=Dialog.openUrl("新增员工", ctxPath + '/modules/sys/user/user_add.html',{area : ['900px','700px'],
            maxmin: true,
            end: function() {
                searcherBS.refresh();
            }
        });
        layer.full(index);
    }

    /**
     * 编辑
     */
    function toEditUser() {
        var rowDatas = searcherBS.getSelectedRows("userId");
        if (rowDatas.length != 1) {
            Dialog.errorMsg("请选择一行进行编辑");
            return;
        }
        if (rowDatas == 1) {
            Dialog.errorMsg("您无权修改超级管理员信息");
        } else{
            var index = Dialog.openUrl("编辑员工", ctxPath + '/sys/user/toEdit/'+rowDatas,
                {area : ['900px','700px'],
                  end: function () {
                    //刷新列表
                      searcherBS.refresh();
                  }
                });
            layer.full(index)
        }

    }

    function deleteUser() {
        var rowDatas = searcherBS.getSelectedRows("userId");
        if (rowDatas.length < 1) {
            Dialog.errorMsg("请至少选择一行");
            return;
        }
        Dialog.confirm('确定删除？', function(index){
            Page.ajaxPOST(ctxPath + "/sys/user/delete", {userIds: rowDatas}, function () {
                Dialog.msg("操作成功", function () {
                    searcherBS.refresh();
                });
            });
        });
    }

    //重置密码为身份证后6位
    function resetPwd() {
        var rowDatas = searcherBS.getSelectedRows("userId");
        if (rowDatas.length != 1) {
            Dialog.errorMsg("请选择一行");
            return;
        }
        Dialog.confirm('确定重置密码为 123456 ？', function(index){
            Page.ajaxPOST(ctxPath + "/sys/user/resetPwd/"+rowDatas, null, function () {
                Dialog.msg("操作成功", function () {
                    searcherBS.refresh();
                });
            });
        });
    }

    /**
     * 启用
     */
    function use() {
        var rowDatas = searcherBS.getSelectedRows("userId");
        if (rowDatas.length != 1) {
            Dialog.errorMsg("请选择一行");
            return;
        }
        Dialog.confirm('确定启用该员工？', function(index){
            Page.ajaxPOST(ctxPath + "/sys/user/use/"+rowDatas, null, function () {
                Dialog.msg("操作成功", function () {
                    searcherBS.refresh();
                });
            });
        });
    }
    /**
     * 禁用
     */
    function unUse() {
        var rowDatas = searcherBS.getSelectedRows("userId");
        if (rowDatas.length != 1) {
            Dialog.errorMsg("请选择一行");
            return;
        }
        Dialog.confirm('确定禁用该员工？', function(index){
            Page.ajaxPOST(ctxPath + "/sys/user/unUse/"+rowDatas, null, function () {
                Dialog.msg("操作成功", function () {
                    searcherBS.refresh();
                });
            });
        });
    }
</script>
</body>
</html>